package com.example.demo.mapper;

import com.example.demo.entity.Course;
import com.example.demo.entity.CourseRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CourseRelationMapper extends JpaRepository<CourseRelation, String> {
    @Query(name="findByRoomAndPeriod",nativeQuery = true,value="select * from courserelation where period=:period and rname=:rname")
    CourseRelation findByRoomAndPeriod (int period, String rname);

    @Query(name="findByTeacher",nativeQuery = true,value="select * from courserelation where period=:period and tid=:tid")
    CourseRelation findByTeacher (int period, String tid);

    @Query(name="findByTeacherAndPeriod",nativeQuery = true,value="select count(*) cnt from courserelation where period in (:period) and tid=:tid")
    int findByTeacherAndPeriod (List<Integer> period, String tid);

    @Query(name="findByRoomAndPeriods",nativeQuery = true,value="select count(*) cnt from courserelation where period in (:period) and rname=:rname")
    int findByRoomAndPeriods (List<Integer> period, String rname);

    @Query(name="findBy", nativeQuery = true, value = "select * from courserelation where  rname= :rname")
    List<CourseRelation> findByRoom(String rname);

    @Query(name="findByTid",nativeQuery = true,value="select * from courserelation where tid=:tid")
    List<CourseRelation> findByTid(String tid);

}
